package com.mew.auc.controller;

import com.mew.common.dc.redis.AucRedisService;
import com.mew.common.rest.bo.MewSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class MewSessionController {

    @Autowired
    private AucRedisService aucRedisService;

    //重要接口
    @GetMapping(value = "/get/{uid}")
    @ResponseBody
    public MewSession getSession(@PathVariable("uid") long uid){
        MewSession session = aucRedisService.getSession(uid);
        return null == session ? new MewSession() : session;
    }

    @GetMapping(value = "/tmsoff/{sid}/{servetype}")
    @ResponseBody
    public Integer tmsoff(@PathVariable("sid") int sid, @PathVariable("servetype") int servetype){
        log.info("tmsOff： sid: {} serverType: {}", sid, servetype);
        List<MewSession> sessions = aucRedisService.findOnlineBySid(sid, servetype);
        if (null == sessions){
            return 1;
        }
        log.info("tmsOff： sid: {} serverType: {}  sessionSize {}", sid, servetype, sessions.size());
        for (MewSession session : sessions){
            aucRedisService.offlineSession(session.uid);
        }
        return 1;
    }



}
